package com.example.administrator.yuejian2.VLayoutAdapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.example.administrator.yuejian2.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GridAdapter extends DelegateAdapter.Adapter {

    private LayoutHelper helper;
    private Context context;

    public GridAdapter(Context context, LayoutHelper helper) {
        this.context = context;
        this.helper = helper;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return helper;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.grid_item, parent, false);
        return new GridViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        GridViewHolder viewHolder=(GridViewHolder) holder;
        viewHolder.gridImageview.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.idea));
        viewHolder.gridTextview.setText("想法");
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"第"+position+"个",Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 4;
    }


    class GridViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.grid_imageview)
        ImageView gridImageview;
        @BindView(R.id.grid_textview)
        TextView gridTextview;
        public GridViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
